<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:sec="http://www.springframework.org/security/facelets/tags">

	<ui:composition template="/faces/manager/xhtml/templates/template.xhtml">
		<ui:define name="manager-content">
			<table id="manager-content-panel" cellpadding="0" cellspacing="1">
				<tr>
					<td id="manager-content-header">
						<h:form>		
							<p:breadCrumb style="width:810px;">
								<p:menuitem value="#{msg['manager.menu.navigator.home']}"/>
								<p:menuitem ajax="false" value="#{msg['manager.menu.navigator.admin']}" action="/faces/manager/xhtml/main.xhtml" />
								<p:menuitem value="#{msg['manager.menu.navigator.anuncio']}" />
							</p:breadCrumb>	
						</h:form>
					</td>
				</tr>
				<tr>
					<td id="manager-content-body">
						<h:form id="formAnuncio" prependId="false">	
							<p:growl id="showMessages" showDetail="true" />
							<p:fieldset legend="#{msg['manager.menu.left.admin.anuncio.title']}" styleClass="manager-fieldset-content">
								<table id="panel-buttons" cellpadding="0" cellspacing="0">
									<tr>
										<td>	
											<p:inputText id="searchTerm" value="#{anuncioController.searchField}" styleClass="inputTextGrid"/>
											<p:watermark for="searchTerm" value="#{msg['manager.menu.left.admin.anuncio.placeholder']}" />
											<p:spacer width="5px"/>
											<p:commandButton value="#{msg['search.menu.button.buscar']}" actionListener="#{anuncioController.search}" update=":formAnuncio:anuncio-panel" ajax="true" icon="search-button"/>
											<p:spacer width="10px"/>									
											<p:commandButton value="#{msg['manager.anuncio.button.create']}" action="#{anuncioController.create}" ajax="false" icon="add-button" disabled="#{usuarioController.limiteAnuncios}"/>
											<p:spacer width="10px"/>
											<p:commandButton id="button-alterar" value="#{msg['manager.anuncio.button.update']}" action="#{anuncioController.edit}" ajax="false" icon="edit-button" 
												disabled="#{!anuncioController.selectedAnuncio}"/>
											<p:spacer width="10px"/>
											<p:commandButton id="button-detalhes" value="#{msg['manager.anuncio.button.visaoDetalhada']}" actionListener="#{anuncioController.anuncioDetalhado}"  
												ajax="true" icon="search-button" update=":formAnuncio:display-detail :formAnuncio:showMessages" oncomplete="anuncioDialog.show();"  
												disabled="#{!anuncioController.selectedAnuncio}"/>																		
										</td>
									</tr>
								</table>
								<p:spacer height="10px"/>
								<p:outputPanel id="anuncio-panel">
								 	<p:dataTable 
										var="anuncio" 
										value="#{anuncioController.lazyModelAnuncio}" 										 
										rows="#{anuncioController.pageSize}" 
										paginator="true"										
										selection="#{anuncioController.anuncio}"
										emptyMessage="#{msg['messages.list.not.found']}">
										
										<p:ajax event="rowSelect" update=":formAnuncio:button-detalhes :formAnuncio:button-alterar" listener="#{anuncioController.onSelectedRow}"/>
										<p:ajax event="page" update=":formAnuncio:button-detalhes :formAnuncio:button-alterar" listener="#{anuncioController.onPaged}"/>  
										<p:column selectionMode="single"  style="width:18px" />
										
										<p:column style="width:40px;text-align:center;" headerText="#{msg['manager.anuncio.list.grid.column.codigo']}" >
											<h:outputText value="#{anuncio.id}" />
										</p:column>
										
										<p:column headerText="#{msg['manager.anuncio.list.grid.column.empresa.nome']}" >
											<h:outputText value="#{anuncio.empresa.pessoaJuridica.nome}" />
										</p:column>
										
										<p:column headerText="#{msg['manager.anuncio.list.grid.column.ramo']}" >
											<h:outputText value="#{anuncio.ramo.nome}" />
										</p:column>
										
										<p:column headerText="#{msg['manager.anuncio.list.grid.column.servico']}" >
											<h:outputText value="#{anuncio.servico.nome}" />
										</p:column>
										
										<sec:ifAnyGranted roles="ADMIN,IMOBILIARIA">
											<p:column styleClass="view-column-lancamento" headerText="#{msg['manager.anuncio.list.grid.column.lancamento']}" >
												<h:outputText value="#{msg['manager.anuncio.list.label.lancamento.sim']}" rendered="#{anuncio.lancamento}"  />
												<h:outputText value="#{msg['manager.anuncio.list.label.lancamento.nao']}" rendered="#{!anuncio.lancamento}"  />
											</p:column>
										</sec:ifAnyGranted>										
										
										<p:column style="text-align:center;" headerText="#{msg['manager.anuncio.list.grid.column.status']}">										
											<h:selectBooleanCheckbox value="#{anuncio.ativo}">
												<p:ajax event="change" listener="#{anuncioController.updateStatusAnuncio}" execute="@this" update=":formAnuncio:showMessages"/>												
											</h:selectBooleanCheckbox>																					
										</p:column>	
										
										<p:column  styleClass="view-column-image">
											<p:commandLink oncomplete="albumDialog.show();" update=":formAnuncio:display-album" rendered="#{!anuncio.albumIsEmpty}">
												<h:graphicImage value="#{resource['images:icons/16x16/image.png']}" />  
								                <f:setPropertyActionListener value="#{anuncio}" target="#{anuncioController.anuncio}"/>  
								            </p:commandLink>  
										</p:column>															
										
									</p:dataTable>
								</p:outputPanel>
								<p:spacer height="10px"/>								
							</p:fieldset>
				            
				            <p:dialog header="#{msg['manager.anuncio.album.title']}" widgetVar="albumDialog" resizable="false" 
					        	modal="true" styleClass="dialog" showEffect="clip" position="top" width="600" height="450">        	
					        	<p:outputPanel id="display-album">					        		
					        		<p:commandButton type="button" onclick="switcherAnuncio.previous();" icon="ui-icon-circle-triangle-w" />  
									<p:spacer height="10px;" width="10px"/>
									<p:commandButton type="button" onclick="switcherAnuncio.next();" icon="ui-icon-circle-triangle-e"/>  
									
									<p:separator style="width:100%;height:1px;" />
									
									<p:imageSwitch effect="wipe" widgetVar="switcherAnuncio" slideshowAuto="false" style="display: block;margin-left: auto;margin-right: auto;">  
									    <ui:repeat value="#{anuncioController.anuncio.album}" var="image">  
									        <p:graphicImage value="#{image.originalImage}"/>  
									    </ui:repeat>  
									</p:imageSwitch> 						        		
					        	</p:outputPanel>        	
					        </p:dialog>
				            
														
							<p:dialog header="#{msg['manager.anuncio.detalhado.title']}" widgetVar="anuncioDialog" resizable="false"  
				              width="540" modal="true">  
				  				
				  				<p:outputPanel id="display-detail">
					        		<p:panel id="empresa">
					        			<table cellpadding="0" cellspacing="0">
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.cliente']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.cliente.pessoa.nome}"  /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.ramo']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.ramo.nome}"  /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.servico']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.servico.nome}"  /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.empresa.nome']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.pessoaJuridica.nome}"  /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.empresa.razaoSocial']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.pessoaJuridica.razaoSocial}"  /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.empresa.cnpj']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.pessoaJuridica.cnpj}"  /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.descricao']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.descricao}"  /></td>
					        				</tr>					        				
					        			</table>
					        		</p:panel>
					        		<p:spacer height="5px"/>
					        		<p:panel id="contato">
					        			<table cellpadding="0" cellspacing="0">
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.contato.email.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.email}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.contato.site.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.site}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.telefone.celular.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.telefoneCelular}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.telefone.fixo.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.telefoneFixo}" /></td>
					        				</tr>
					        			</table>					        		
					        		</p:panel>
					        		<p:spacer height="5px"/>
					        		<p:panel id="endereco">
					        			<table cellpadding="0" cellspacing="0">
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.cep.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.cep}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.rua.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.rua}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.numero.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.numero}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.complemento.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.complemento}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.edificio.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.edificio}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.bairro.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.bairro}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.municipio.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.municipio.nome}" /></td>
					        				</tr>
					        				<tr>
					        					<td class="view-column-label"><h:outputText value="#{msg['manager.anuncio.detalhado.endereco.estado.label']}:" /></td>
					        					<td class="view-column-value"><h:outputText value="#{anuncioController.anuncio.empresa.endereco.municipio.estado.sigla}" /></td>
					        				</tr>
					        			</table>
					        		</p:panel>
					        		
			              		</p:outputPanel>		              		
			              		
		    				</p:dialog> 
						</h:form>
					</td>
				</tr>
			</table>
		</ui:define>
	
	</ui:composition>
</html>